package Views;

import Model.Grid;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Observable;

/**
 *
 * @author KOK Leng-Steven & RIEU Simon
 */
public class CircleView extends GridView
{
    public CircleView(Grid grid)
    {
        super(grid);
        strategies = new Circle[this.size][this.size];
        for (int i = 0; i < this.size; i++)
        {
            for (int j = 0; j < this.size; j++)
            {
                strategies[i][j] = new Circle(20, 20, i * 20, j * 20);
            }
        }
        this.colorCircleView(grid);
    }

    @Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        for (int i = 0; i < this.size; i++)
        {
            for (int j = 0; j < this.size; j++)
            {
                strategies[i][j].draw(g);
            }
        }
    }

    @Override
    public void update(Observable o, Object o1)
    {
      
        if (o instanceof Grid)
        {
            Grid grid = (Grid) o;
            this.colorCircleView(grid);
        }
    }

    private void colorCircleView(Grid grid)
    {
        Circle c;

        //everybody have a white fill by default
        for (int i = 0; i < this.size; i++)
        {
            for (int j = 0; j < this.size; j++)
            {
                c = (Circle) strategies[i][j];
                c.setColor(Color.WHITE);

            }
        }

        //we fill in red the circle where the avatar currenty is
        c = (Circle) strategies[grid.getAvatar().getI()][grid.getAvatar().getJ()];
        c.setColor(Color.RED);

        //we fill the circles where there are byStanders
        for (int i = 0; i < grid.getByStanders().size(); i++)
        {
            c = (Circle) strategies[grid.getByStanders().get(i).getI()][grid.getByStanders().get(i).getJ()];
            c.setColor(Color.GRAY);
            //If the avatar is seeing someone we change the color GRAY to BLUE
            if (grid.getByStanders().get(i).isAvatarSeeingByStander())
            {
                c.setColor(Color.BLUE);
            }
        }
        //update the painting
        this.repaint();
    }
    
    public void test()
    {
        this.setVisible(false);
    }
}
